import com.dmall.list.LinkedList;
import com.dmall.list.LoopTwoWayLinkedList;
import com.dmall.list.RecursiveLinkedList;
import com.dmall.list.TwoWayLinkedList;
import org.junit.Test;

public class Main {

    @Test
    public void test1() {
        LinkedList<Integer> linkedList = new LinkedList<>();
        for (int i = 0; i < 5; i++) {
            linkedList.addFirst(i);
            System.out.println(linkedList);
        }

        linkedList.add(2, 666);
        System.out.println(linkedList);

        linkedList.addLast(999);
        System.out.println(linkedList);

        linkedList.remove(2);
        System.out.println(linkedList);

        linkedList.removeFirst();
        System.out.println(linkedList);

        linkedList.removeLast();
        System.out.println(linkedList);
    }

    @Test
    public void test2() {
        TwoWayLinkedList<Integer> linkedList = new TwoWayLinkedList<>();
        for (int i = 0; i < 5; i++) {
            linkedList.addFirst(i);
            System.out.println(linkedList);
        }

        linkedList.add(2, 666);
        System.out.println(linkedList);

        linkedList.remove(2);
        System.out.println(linkedList);

        linkedList.removeFirst();
        System.out.println(linkedList);

        linkedList.removeLast();
        System.out.println(linkedList);
    }

    @Test
    public void test3() {
        LoopTwoWayLinkedList<Integer> linkedList = new LoopTwoWayLinkedList<>();
        for (int i = 0; i < 5; i++) {
            linkedList.addFirst(i);
            System.out.println(linkedList);
        }

        linkedList.add(2, 666);
        System.out.println(linkedList);

        linkedList.addLast(999);
        System.out.println(linkedList);

        linkedList.removeLast();
        System.out.println(linkedList);

        linkedList.removeFirst();
        System.out.println(linkedList);

        linkedList.remove(2);
        System.out.println(linkedList);
    }

    @Test
    public void test4() {
        RecursiveLinkedList<Integer> linkedList = new RecursiveLinkedList<>();
        for (int i = 0; i < 5; i++) {
            linkedList.addFirst(i);
            System.out.println(linkedList);
        }

        linkedList.add(2, 666);
        System.out.println(linkedList);

        linkedList.addLast(999);
        System.out.println(linkedList);

        Integer preUpdate = linkedList.set(3, 888);
        System.out.println(preUpdate);

        Integer getValue = linkedList.get(3);
        System.out.println(getValue);

        linkedList.removeLast();
        System.out.println(linkedList);

        linkedList.removeFirst();
        System.out.println(linkedList);

        linkedList.remove(2);
        System.out.println(linkedList);

        linkedList.reverse();
        System.out.println(linkedList);
    }

    @Test
    public void test5() {
        LinkedList<Integer> list = new LinkedList<>();
        for (int i = 0; i < 5; i++) {
            list.addFirst(i);
        }
        System.out.println(list);
        list.removeNthFromEnd(4);
        System.out.println(list);
    }
}
